<template>
  <div class="reportFormPage">
    <div class="report-dom horizontal">
      <el-row>
        <el-col :span="5" :offset="19">
          <div class="pageNumBox">
            <span>第</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.page }}&nbsp;</span>
            <span>页，共</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.totalPage }}&nbsp;</span>
            <span>页</span>
          </div>
        </el-col>
      </el-row>
      <div class="topTwoBox">
        <div class="centerName">钢材重量偏差试验检测记录表</div>
        <div class="codeText">JGLQ15001</div>
      </div>
      <div class="threeTopBox">
        <div class="left-border">
          <div class="box-title">检测单位名称：</div>
          <div class>{{ form.jiancdwmc }}</div>
        </div>
        <div class="right-border">
          <span>记录编号：</span>
          <span v-if="isPdf" class="placeholder">{{ form.jilbh }}</span>
          <el-input class="code-input" v-else type="text" v-model="form.jilbh" @focus="handleFocus('jilbh')" />
        </div>
      </div>
      <div class="table-border">
        <!------------------------------表头-------------------------->
        <table height="160px" class="top-table">
          <tbody>
            <tr>
              <td height="30" align="center" width="15%">
                <span style="width: 90px; display: inline-block">工程名称</span>
              </td>
              <td width="35%" class="text-center">
                <span>{{ form.gongcmc }}</span>
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">工程部位/用途</span>
              </td>
              <td width="35%" class="text-center">
                <span>{{ form.gongcbwyt }}</span>
              </td>
            </tr>
            <tr>
              <td height="30" align="center">样品信息</td>
              <td class="specimen-border" colspan="3">
                <span>样品名称：</span>
                <span :class="{ placeholder: !form.yangpmc }">{{ form.yangpmc }}</span>
                <span>；样品编号：</span>
                <span :class="{ 'placeholder-long': !form.yangpbh }">{{ form.yangpbh }}</span>
                <span>；样品数量：</span>
                <span :class="{ placeholder: !form.yangpsl }">{{ form.yangpsl }}</span>
                <span>；样品状态：</span>
                <span :class="{ placeholder: !form.yangpzt }">{{ form.yangpzt }}</span>
                <span>；来样时间：</span>
                <span :class="{ placeholder: !form.yangpsj }">{{ form.yangpsj }}</span>
              </td>
            </tr>

            <tr>
              <td height="25" align="center" width="15%">
                <span style="width: 90px; display: inline-block">试验检测日期</span>
              </td>
               <!-- <td width="35%" class="text-center">{{ form.shiyjcrq }}</td> -->                                            
 <td width="35%" class="text-center">
      <el-input v-model="form.shiyjcrq" />
</td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">试验条件</span>
              </td>
              <td v-if="isPdf" width="35%">
                温度：
                <span style="display: inline-block; width: 10%">{{ form.shiytjwd }}</span>
                ℃；湿度：
                <span style="display: inline-block; width: 10%">{{ form.shiytjsd }}</span
                >%RH
              </td>
              <td v-else width="35%">
                温度：
                <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shiytjwd" style="width: 15%" />℃；湿度：
                <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shiytjsd" style="width: 15%" />%RH
              </td>
            </tr>

            <tr>
              <td height="40" align="center" width="15%">
                <span style="width: 90px; display: inline-block">检测依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.jiancyj }}</span>
                <el-input v-else type="textarea" v-model="form.jiancyj" :rows="2" class="mark" @dblclick.native="showBsJiancyjView" readonly />
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">判定依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.pandyj }}</span>
                <el-input v-else type="textarea" v-model="form.pandyj" :rows="2" @dblclick.native="showBsJudgeBaseView" @focus="handleFocus('pandyj')" class="mark" />
              </td>
            </tr>
            <tr class="bottom-border">
              <td height="30" align="center">
                <div>主要仪器设备</div>
                <div>名称及编号</div>
              </td>
              <td colspan="3">
                <span v-if="isPdf">{{ form.zhuyyqsbmcjbh }}</span>
                <el-input v-else type="textarea" :rows="2" v-model="form.zhuyyqsbmcjbh" class="height100 width100 mark" @dblclick.native="showBsInstrumentView" readonly></el-input>
              </td>
            </tr>
          </tbody>
        </table>
        <!------------------------------表中-------------------------->
        <table height="300px" class="middle-table">
          <tbody>
            <tr height="40">
              <td>取样地点</td>
              <td colspan="4"><el-input type="text" v-model="form.quydd" @keydown.native="handleKeyDown($event, 0, 0)" :ref="'0_0'" /></td>
              <td>代表数量</td>
              <td colspan="5"><el-input type="text" v-model="form.daibsl" @keydown.native="handleKeyDown($event, 0, 1)" :ref="'0_1'" /></td>
            </tr>
            <tr height="40">
              <td>规格牌号</td>
              <td colspan="4"><el-input type="text" v-model="form.guigxh" @keydown.native="handleKeyDown($event, 1, 0)" :ref="'1_0'" /></td>
              <td>批号</td>
              <td colspan="5"><el-input type="text" v-model="form.pih" @keydown.native="handleKeyDown($event, 1, 1)" :ref="'1_1'" /></td>
            </tr>
            <tr height="40">
              <td>生产厂家</td>
              <td colspan="10"><el-input type="text" v-model="form.cd" @keydown.native="handleKeyDown($event, 2, 0)" :ref="'2_0'" /></td>
            </tr>
            <tr height="40">
              <td rowspan="2">公称直径(mm)</td>
              <td rowspan="2">公称截面积(mm²)</td>
              <td colspan="6">样品长度(mm)</td>
              <td rowspan="2">样品重量(g)</td>
              <td rowspan="2">理论重量(kg/m)</td>
              <td rowspan="2">重量偏差(%)</td>
            </tr>
            <tr height="40">
              <td>1</td>
              <td>2</td>
              <td>3</td>
              <td>4</td>
              <td>5</td>
              <td>总长度</td>
            </tr>
            <tr height="40">
              <td width="10%">
                <el-select clearable v-model="form.gongczj1" class="hide-icon2 height100" placeholder @change="gongczjChange('gongczj1', 'gongcjmj1', 'lilzl1', 'zhonglpc1')">
                  <el-option v-for="(item, index) in gongczjList" :key="index" :label="item.diameter" :value="item.deId"></el-option>
                </el-select>
                <!-- <el-input type="text" v-model="form.gongczj1" /> -->
              </td>
              <td width="10%"><el-input type="text" v-model="form.gongcjmj1" disabled /></td>
              <td style="width: calc(80% / 9 * 1)">
                <el-input type="text" v-model="form.yangpcd11" @change="countYangpcd(1, form.yangpcd11)" @keydown.native="handleKeyDown($event, 3, 0)" :ref="'3_0'" />
              </td>
              <td style="width: calc(80% / 9 * 1)">
                <el-input type="text" v-model="form.yangpcd12" @change="countYangpcd(1, form.yangpcd12)" @keydown.native="handleKeyDown($event, 3, 1)" :ref="'3_1'" />
              </td>
              <td style="width: calc(80% / 9 * 1)">
                <el-input type="text" v-model="form.yangpcd13" @change="countYangpcd(1, form.yangpcd13)" @keydown.native="handleKeyDown($event, 3, 2)" :ref="'3_2'" />
              </td>
              <td style="width: calc(80% / 9 * 1)">
                <el-input type="text" v-model="form.yangpcd14" @change="countYangpcd(1, form.yangpcd14)" @keydown.native="handleKeyDown($event, 3, 3)" :ref="'3_3'" />
              </td>
              <td style="width: calc(80% / 9 * 1)">
                <el-input type="text" v-model="form.yangpcd15" @change="countYangpcd(1, form.yangpcd15)" @keydown.native="handleKeyDown($event, 3, 4)" :ref="'3_4'" />
              </td>
              <td style="width: calc(80% / 9 * 1)"><el-input type="text" v-model="form.yangpcdzcd1" disabled /></td>
              <td style="width: calc(80% / 9 * 1)">
                <el-input type="text" v-model="form.yangpzl1" @change="handleYangpzl(1, form.yangpzl1)" @keydown.native="handleKeyDown($event, 3, 5)" :ref="'3_5'" />
              </td>
              <td style="width: calc(80% / 9 * 1)"><el-input type="text" v-model="form.lilzl1" disabled /></td>
              <td style="width: calc(80% / 9 * 1)"><el-input type="text" v-model="form.zhonglpc1" disabled /></td>
            </tr>
            <tr height="40">
              <td>
                <el-select clearable v-model="form.gongczj2" class="hide-icon2 height100" placeholder @change="gongczjChange('gongczj2', 'gongcjmj2', 'lilzl2', 'zhonglpc2')">
                  <el-option v-for="(item, index) in gongczjList" :key="index" :label="item.diameter" :value="item.deId"></el-option>
                </el-select>
              </td>
              <td><el-input type="text" v-model="form.gongcjmj2" disabled /></td>
              <td><el-input type="text" v-model="form.yangpcd21" @change="countYangpcd(2, form.yangpcd21)" @keydown.native="handleKeyDown($event, 4, 0)" :ref="'4_0'" /></td>
              <td><el-input type="text" v-model="form.yangpcd22" @change="countYangpcd(2, form.yangpcd22)" @keydown.native="handleKeyDown($event, 4, 1)" :ref="'4_1'" /></td>
              <td><el-input type="text" v-model="form.yangpcd23" @change="countYangpcd(2, form.yangpcd23)" @keydown.native="handleKeyDown($event, 4, 2)" :ref="'4_2'" /></td>
              <td><el-input type="text" v-model="form.yangpcd24" @change="countYangpcd(2, form.yangpcd24)" @keydown.native="handleKeyDown($event, 4, 3)" :ref="'4_3'" /></td>
              <td><el-input type="text" v-model="form.yangpcd25" @change="countYangpcd(2, form.yangpcd25)" @keydown.native="handleKeyDown($event, 4, 4)" :ref="'4_4'" /></td>
              <td><el-input type="text" v-model="form.yangpcdzcd2" disabled /></td>
              <td><el-input type="text" v-model="form.yangpzl2" @change="handleYangpzl(2, form.yangpzl2)" @keydown.native="handleKeyDown($event, 4, 5)" :ref="'4_5'" /></td>
              <td><el-input type="text" v-model="form.lilzl2" disabled /></td>
              <td><el-input type="text" v-model="form.zhonglpc2" disabled /></td>
            </tr>
            <tr height="40">
              <td>
                <el-select v-model="form.gongczj3" clearable class="hide-icon2 height100" placeholder @change="gongczjChange('gongczj3', 'gongcjmj3', 'lilzl3', 'zhonglpc3')">
                  <el-option v-for="(item, index) in gongczjList" :key="index" :label="item.diameter" :value="item.deId"></el-option>
                </el-select>
              </td>
              <td><el-input type="text" v-model="form.gongcjmj3" disabled /></td>
              <td><el-input type="text" v-model="form.yangpcd31" @change="countYangpcd(3, form.yangpcd31)" @keydown.native="handleKeyDown($event, 5, 0)" :ref="'5_0'" /></td>
              <td><el-input type="text" v-model="form.yangpcd32" @change="countYangpcd(3, form.yangpcd32)" @keydown.native="handleKeyDown($event, 5, 1)" :ref="'5_1'" /></td>
              <td><el-input type="text" v-model="form.yangpcd33" @change="countYangpcd(3, form.yangpcd33)" @keydown.native="handleKeyDown($event, 5, 2)" :ref="'5_2'" /></td>
              <td><el-input type="text" v-model="form.yangpcd34" @change="countYangpcd(3, form.yangpcd34)" @keydown.native="handleKeyDown($event, 5, 3)" :ref="'5_3'" /></td>
              <td><el-input type="text" v-model="form.yangpcd35" @change="countYangpcd(3, form.yangpcd35)" @keydown.native="handleKeyDown($event, 5, 4)" :ref="'5_4'" /></td>
              <td><el-input type="text" v-model="form.yangpcdzcd3" disabled /></td>
              <td><el-input type="text" v-model="form.yangpzl3" @change="handleYangpzl(3, form.yangpzl3)" @keydown.native="handleKeyDown($event, 5, 5)" :ref="'5_5'" /></td>
              <td><el-input type="text" v-model="form.lilzl3" disabled /></td>
              <td><el-input type="text" v-model="form.zhonglpc3" disabled /></td>
            </tr>
          </tbody>
        </table>
        <!------------------------------附加声明-------------------------->
        <table height="30px" class="bottom-table">
          <tr>
            <td>
              <span v-if="isPdf" class="textarea-span">{{ form.fujsm }}</span>
              <el-input v-else type="textarea" :rows="2" v-model="form.fujsm" @focus="handleFocus('fujsm')" />
            </td>
          </tr>
        </table>
      </div>
      <!------------------------------表底-------------------------->
      <table height="22px" class="transparent">
        <tbody>
          <tr>
            <td width="10%" align="right">检测：</td>
            <td width="15%" align="left"></td>
            <td width="10%" align="right">记录：</td>
            <td width="15%" align="left"></td>
            <td width="10%" align="right">复核：</td>
            <td align="left" width="15%"></td>
            <td width="10%">日期：</td>
            <td align="left" width="15%">
              <div style="display: inline-block; margin-left: 20px">年</div>
              <div style="display: inline-block; margin-left: 20px">月</div>
              <div style="display: inline-block; margin-left: 20px">日</div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <bs-instrument-view ref="bsInstrumentViewRef" @select="selectInstrument"></bs-instrument-view>
    <bs-jiancyj-view ref="bsJiancyjViewRef" @select="selectJiancyj" :syType="syType"></bs-jiancyj-view>
    <bs-judge-base-view ref="bsJudgeBaseViewRef" @select="selectJudge" :syType="syType"></bs-judge-base-view>
  </div>
</template>

<script>
import { listGczlpcjlbBsInfo, getGczlpcjlbBsInfo, delGczlpcjlbBsInfo, addGczlpcjlbBsInfo, updateGczlpcjlbBsInfo } from "@/api/report_gc/gczlpcjlbBsInfo";
import BsInstrumentView from "@/views/dept/bsInstrument/BsInstrumentView.vue";
import decimal from "@/utils/big-decimal";
import BsJiancyjView from "@/views/sycs/bsJiancyj/BsJiancyjView";
import { handleFocus, handleKeyDown } from "@/views/reportForms/utils";
import BsJudgeBaseView from "@/views/sycs/bsJudgeBase/BsJudgeBaseView.vue";
import Bus from "@/utils/bus";
import { listBySyTypeId } from "@/api/sycs/dataBase";

export default {
  name: "gczlpcjlb",
  components: {
    BsInstrumentView,
    BsJiancyjView,
    BsJudgeBaseView
  },
  props: {
    excelId: {
      type: [String, Number],
      default: () => ""
    },
    syType: {
      type: [String, Number],
      default: () => ""
    },
    page: {
      type: Number,
      default: () => 0
    },
    isPdf: {
      type: Boolean,
      default: () => false
    }
  },
  data() {
    return {
      gongczjList: [],
      params: {},
      query: {},
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        excelId: [{ required: true, message: "主键不能为空", trigger: "blur" }]
      }
    };
  },

  created() {
    this.getInfo();
    this.getGongczjList();
  },
  methods: {
    getGongczjList() {
      listBySyTypeId({ syYjId: "1818216586924834817" }).then((response) => {
        const data = response.data;
        this.gongczjList = data.page.records;
      });
    },
    gongczjChange(name, setName1, setName2, setName3) {
      const info = this.gongczjList.find((item) => item.deId == this.form[name]);
      if (!info) {
        this.form[name] = null;
        this.form[setName1] = null;
        this.form[setName2] = null;
        this.form[setName3] = null;
        return;
      }
      this.form[name] = info.diameter;
      this.form[setName1] = info.area;
      this.form[setName2] = info.weight;
    },
    // 获取详情
    getInfo() {
      if (!this.excelId) {
        return;
      }
      getGczlpcjlbBsInfo(this.excelId || this.$defaultExcelId).then((response) => {
        this.form = response.data;
        if (!this.form.fujsm) {
          this.form.fujsm = "附加声明：";
        }
      });
    },

    // 显示检测依据列表
    showBsJiancyjView() {
      this.$refs.bsJiancyjViewRef.init(this.form.jiancyjIds);
    },
    // 检测依据选择
    selectJiancyj(info) {
      this.form.jiancyj = info.label;
      this.form.jiancyjIds = info.ids;
      Bus.$emit("setGcsyjcBgJiancyj", { jiancyj: this.form.jiancyj, jiancyjIds: this.form.jiancyjIds });
    },

    // 显示判定依据列表
    showBsJudgeBaseView() {
      this.$refs.bsJudgeBaseViewRef.init(this.form.pandyjIds);
    },
    // 判断依据选择
    selectJudge(info) {
       this.form.pandyjIds = info.ids;
      this.form.pandyj = info.label;
    },

    // 显示仪器列表
    showBsInstrumentView() {
      this.$refs.bsInstrumentViewRef.init(this.form.shebIds);
    },
    // 仪器选择
    selectInstrument(info) {
      this.form.zhuyyqsbmcjbh = info.label;
      this.form.shebIds = info.ids;
      Bus.$emit("setGcsyjcBgZhuyyqsbmcjbh", { zhuyyqsbmcjbh: this.form.zhuyyqsbmcjbh, shebIds: this.form.shebIds });
    },

    handleFocus(event) {
      handleFocus(event, this.page, this.form[event]);
    },
    countYangpcd(num, val) {
      let data =
        Number(this.form["yangpcd" + num + 1]) +
        Number(this.form["yangpcd" + num + 2]) +
        Number(this.form["yangpcd" + num + 3]) +
        Number(this.form["yangpcd" + num + 4]) +
        Number(this.form["yangpcd" + num + 5]);
      this.form["yangpcdzcd" + num] = data || null;
    },
    handleYangpzl(num, val) {
      if (this.form["yangpcdzcd" + num] != null) {
        return;
      }
      let F = Number(this.form["yangpcdzcd" + num]);
      let G = Number(val);
      let H = Number(this.form["lilzl" + num]);
      let data = (100 * (G - F * H)) / (F * H);
      this.form["zhonglpc" + num] = data ? decimal.round(Number(data), 1) : null;
      let objData = {
        1: 0,
        2: 2,
        3: 4
      };
      Bus.$emit("setGcSyZhonglpcForm", { [objData[num]]: this.form["zhonglpc" + num] });
    },
    submitForm() {
      return this.form;
    },
    handleKeyDown(event, rowIndex, colIndex) {
      const maxArr = [1, 1, 0, 5, 5, 5]; // 每一行最多有多少可聚焦输入框（从0开始）
      const ref = handleKeyDown(event, rowIndex, colIndex, maxArr);
      if (this.$refs[ref]) {
        this.$refs[ref].focus();
      }
    }
  }
};
</script>


<style scoped></style>
